﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Web.Api
{
    /// <summary>
    /// 系统的错误代码
    /// </summary>
    public static class ErrorCode
    {
        public const int NoError = 0xFF01;

        /// <summary>
        /// 数据库错误
        /// </summary>
        public const int DB_Error = 0xFF02;

        /// <summary>
        /// 无效的参数
        /// </summary>
        public const int Common_InvalidParameter = 0xFF03;

        /// <summary>
        /// 认证
        /// 认证失败，没有认证信息
        /// Authentication
        /// </summary>
        public const int Auth_NoAuth = 0xFF03;

        /// <summary>
        /// 认证
        /// 认证失败，已超时
        /// </summary>
        public const int Auth_Timeout = 0xFF04;

        #region register
        /// <summary>
        /// 注册,
        /// 无效的电话号码
        /// </summary>
        public const int Register_InvalidPhone = 0x0001;
        /// <summary>
        /// 注册,
        /// 无效的密码
        /// </summary>
        public const int Register_InvalidPassword = 0x0002;
        /// <summary>
        /// 注册,
        /// 无效的验证码
        /// </summary>
        public const int Register_InvalidVerifycode = 0x0003;
        /// <summary>
        /// 注册,
        /// 失败，电话号码已被注册
        /// </summary>
        public const int Register_PhoneRegistered = 0x0004;
        /// <summary>
        /// 注册，
        /// 创建账户失败
        /// </summary>
        public const int Register_CreateAccountError = 0x0005;
        #endregion

        #region login
        /// <summary>
        /// 登录,
        /// 无效的电话号码
        /// </summary>
        public const int Login_InvalidPhone = 0x0006;
        /// <summary>
        /// 登录,
        /// 无效的密码
        /// </summary>
        public const int Login_InvalidPassword = 0x0007;
        /// <summary>
        /// 登录，
        /// 失败，电话没有注册
        /// </summary>
        public const int Login_PhoneNotRegistered = 0x0008;

        /// <summary>
        /// 登录，
        /// 失败，密码错误
        /// </summary>
        public const int Login_PasswordError = 0x0009;

        /// <summary>
        /// 登录，
        /// 失败，账号被锁定
        /// </summary>
        public const int Login_Locked = 0x000A;
        #endregion

        #region send verifycode
        /// <summary>
        /// 发送验证码
        /// 失败，无效的电话号码
        /// </summary>
        public const int SendVerifycode_InvalidPhone = 0x0011;
        /// <summary>
        /// 发送验证码
        /// 失败，电话号码已注册
        /// </summary>
        public const int SendVerifycode_PhoneRegistered = 0x0012;

        /// <summary>
        /// 发送验证码
        /// 失败，电话号码未注册
        /// </summary>
        public const int SendVerifycode_PhoneUnregistered = 0x0013;

        /// <summary>
        /// 发送验证码，
        /// 失败，发送验证码失败
        /// </summary>
        public const int SendVerifycode_SendFailure = 0x0014;
        #endregion

        #region change password
        /// <summary>
        /// 修改密码
        /// 失败，电话号码未注册
        /// </summary>
        public const int ChangePassword_InvalidPhone = 0x0015;
        /// <summary>
        /// 修改密码
        /// 失败，电话号码未注册
        /// </summary>
        public const int ChangePassword_InvalidPassword = 0x0016;
        /// <summary>
        /// 修改密码
        /// 无效的验证码
        /// </summary>
        public const int ChangePassword_InvalidVerifycode = 0x0017;
        /// <summary>
        /// 修改密码
        /// 失败，电话号码未注册
        /// </summary>
        public const int ChangePassword_PhoneUnregistered = 0x0018;
        /// <summary>
        /// 修改密码
        /// 失败，旧密码不正确
        /// </summary>
        public const int ChangePassword_PasswordError = 0x0018;
        #endregion

        #region change name
        /// <summary>
        /// 修改名称
        /// 是吧，错误的名称
        /// </summary>
        public const int ChangeName_InvalidName = 0x0018;
        /// <summary>
        /// 修改名称
        /// 是吧，账号未注册
        /// </summary>
        public const int ChangeName_PhoneUnregistered = 0x0019;
        #endregion

        /// <summary>
        /// 发送好友请求，
        /// 失败，同一个用户
        /// </summary>
        public const int SendFriendsRequest_SameUser = 0x0019;

        /// <summary>
        /// 发送好友请求，
        /// 失败，已存在好友关系
        /// </summary>
        public const int SendFriendsRequest_HasRelation = 0x001A;
        /// <summary>
        /// 发送好友请求，
        /// 失败，发送者不存在
        /// </summary>
        public const int SendFriendsRequest_SenderNotExist = 0x001B;
        /// <summary>
        /// 发送好友请求，
        /// 失败，接收者不存在
        /// </summary>
        public const int SendFriendsRequest_ReceiverNotExist = 0x001C;

        /// <summary>
        /// 同意好友请求
        /// 失败，不存在好友申请
        /// </summary>
        public const int AcceptFriendsRequest_NoRequest = 0x0020;

        /// <summary>
        /// 拒绝好友请求
        /// 失败，不存在好友申请
        /// </summary>
        public const int RejectFriendsRequest_NoRequest = 0x0021;

        #region activity feedback
        /// <summary>
        /// 反馈活动
        /// 失败，活动不存在
        /// </summary>
        public const int ActivityFeedback_NotExist = 0x0022;

        /// <summary>
        /// 反馈活动
        /// 失败，活动还未结束
        /// </summary>
        public const int ActivityFeedback_NotFinished = 0x0022;

        /// <summary>
        /// 反馈活动
        /// 失败，未参加此活动
        /// </summary>
        public const int ActivityFeedback_NotJoined = 0x0023;
        #endregion

        #region join activity
        /// <summary>
        /// 加入活动
        /// 失败，用户不存在
        /// </summary>
        public const int JoinActivity_UserNotExist = 0x0024;
        /// <summary>
        /// 加入活动
        /// 失败，活动不存在
        /// </summary>
        public const int JoinActivity_ActivityNotExist = 0x0025;
        /// <summary>
        /// 加入活动
        /// 失败，活动已结束
        /// </summary>
        public const int JoinActivity_ActivityHasFinished = 0x0026;
        /// <summary>
        /// 加入活动
        /// 失败，活动人员已满
        /// </summary>
        public const int JoinActivity_HasFull = 0x0027;
        /// <summary>
        /// 加入活动
        /// 失败，已经加入，不能再加入
        /// </summary>
        public const int JoinActivity_HasJoined = 0x0028;
        #endregion

        #region leave activity
        /// <summary>
        /// 退出活动
        /// 失败，用户不存在
        /// </summary>
        public const int LeaveActivity_UserNotExist = 0x0029;
        /// <summary>
        /// 退出活动
        /// 失败，活动不存在
        /// </summary>
        public const int LeaveActivity_ActivityNotExist = 0x002A;
        /// <summary>
        /// 退出活动
        /// 失败，活动已结束
        /// </summary>
        public const int LeaveActivity_ActivityHasFinished = 0x002B;
        #endregion

        #region upload image resource
        /// <summary>
        /// 上传图片
        /// 失败，错误的文件类型
        /// </summary>
        public const int UploadImage_InvalidType = 0x002C;
        /// <summary>
        /// 上传图片
        /// 失败，图片太大
        /// </summary>
        public const int UploadImage_TooLarge = 0x002D;
        /// <summary>
        /// 上传图片
        /// 失败，图片保存到文件系统失败
        /// </summary>
        public const int UploadImage_IOError = 0x002E;
        #endregion

        public static string ToString(int code)
        {
            if (code == NoError)
            {
                return "操作成功";
            }
            if (code == DB_Error)
            {
                return "数据库操作出错";
            }
            if (code == Common_InvalidParameter)
            {
                return "无效的参数";
            }
            if (code == Auth_NoAuth)
            {
                return "认证失败，没有认证信息";
            }
            if (code == Auth_Timeout)
            {
                return "认证失败，已超时";
            }
            #region register
            if (code == Register_InvalidPhone)
            {
                return "无效的电话号码";
            }
            if (code == Register_InvalidPassword)
            {
                return "无效的密码";
            }
            if (code == Register_InvalidVerifycode)
            {
                return "无效的验证码";
            }
            if (code == Register_PhoneRegistered)
            {
                return "失败，电话号码已被注册";
            }
            if (code == Register_CreateAccountError)
            {
                return "失败，创建账户失败";
            }
            #endregion

            #region login
            if (code == Login_InvalidPhone)
            {
                return "无效的电话号码";
            }
            if (code == Login_InvalidPassword)
            {
                return "无效的密码";
            }
            if (code == Login_PhoneNotRegistered)
            {
                return "电话没有注册";
            }
            if (code == Login_PasswordError)
            {
                return "密码错误";
            }
            if (code == Login_Locked)
            {
                return "账号被锁定";
            }
            #endregion

            #region send verifycode
            if (code == SendVerifycode_InvalidPhone)
            {
                return "无效的电话号码";
            }
            if (code == SendVerifycode_PhoneRegistered)
            {
                return "电话号码已注册";
            }
            if (code == SendVerifycode_PhoneUnregistered)
            {
                return "电话号码未注册";
            }
            if (code == SendVerifycode_SendFailure)
            {
                return "发送验证码失败";
            }
            #endregion

            #region change password
            if (code == ChangePassword_InvalidPhone)
            {
                return "电话号码未注册";
            }
            if (code == ChangePassword_InvalidPassword)
            {
                return "无效的密码";
            }
            if (code == ChangePassword_InvalidVerifycode)
            {
                return "无效的验证码";
            }
            if (code == ChangePassword_PhoneUnregistered)
            {
                return "电话号码未注册";
            }
            if (code == ChangePassword_PasswordError)
            {
                return "旧密码不正确";
            }
            #endregion

            #region change name
            if (code == ChangeName_InvalidName)
            {
                return "错误的名称";
            }
            if (code == ChangeName_PhoneUnregistered)
            {
                return "账号未注册";
            }
            #endregion

            if (code == SendFriendsRequest_SameUser)
            {
                return "同一个用户";
            }
            if (code == SendFriendsRequest_HasRelation)
            {
                return "已存在好友关系";
            }
            if (code == SendFriendsRequest_ReceiverNotExist)
            {
                return "接收好友请求的用户不存在";
            }
            if (code == SendFriendsRequest_SenderNotExist)
            {
                return "发送好友请求的用户不存在";
            }
            if (code == AcceptFriendsRequest_NoRequest)
            {
                return "不存在好友申请";
            }
            if (code == RejectFriendsRequest_NoRequest)
            {
                return "不存在好友申请";
            }
            #region activity feedback
            if (code == ActivityFeedback_NotExist)
            {
                return "活动不存在";
            }
            if (code == ActivityFeedback_NotFinished)
            {
                return "活动还未结束";
            }
            if (code == ActivityFeedback_NotJoined)
            {
                return "未参加此活动";
            }
            #endregion

            #region join activity
            if (code == JoinActivity_UserNotExist)
            {
                return "用户不存在";
            }
            if (code == JoinActivity_ActivityNotExist)
            {
                return "活动不存在";
            }
            if (code == JoinActivity_ActivityHasFinished)
            {
                return "活动已结束";
            }
            if (code == JoinActivity_HasFull)
            {
                return "活动人员已满";
            }
            if (code == JoinActivity_HasJoined)
            {
                return "不能重复加入";
            }
            #endregion

            #region leave activity
            if (code == LeaveActivity_UserNotExist)
            {
                return "用户不存在";
            }
            if (code == LeaveActivity_ActivityNotExist)
            {
                return "活动不存在";
            }
            if (code == LeaveActivity_ActivityHasFinished)
            {
                return "活动已结束";
            }
            #endregion

            #region upload image resource
            if (code == UploadImage_InvalidType)
            {
                return "错误的文件类型";
            }
            if (code == UploadImage_TooLarge)
            {
                return "图片太大";
            }
            if (code == UploadImage_IOError)
            {
                return "图片保存到文件系统失败";
            }
            #endregion
            return "未知错误";
        }
    }
}
